package com.sgb.kjwl.view.widget;

import android.content.Context;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.view.ui.adapter.shopping.MainBusinessAdapter;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.util.MToast;

import java.util.List;

public class MainBusinessPopWindow extends BasePopWindow {

    private RecyclerView recyclerView;
    private TextView okView;
    private TextView resetView;
    private TextView title;
    private LinearLayout bottomLayout;
    private MainBusinessAdapter mainBusinessAdapter;
    private List<String> test;
    private List<String> selectList;
    private boolean isChange;

    public MainBusinessPopWindow(Context context) {
        super(context, DIR_DOWN_UP);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_skill;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        recyclerView = holder.getPop().findViewById(R.id.skill_list);
        title = holder.getPop().findViewById(R.id.title);
        bottomLayout = holder.getPop().findViewById(R.id.bottom_layout);
        okView = holder.getPop().findViewById(R.id.ok_view);
        resetView = holder.getPop().findViewById(R.id.reset_view);
        okView.setText("取消");
        title.setVisibility(View.GONE);
        okView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dissMiss();
                if (onResultClick != null) {
                    if (selectList == null) {
                        MToast.showToast(mContext, "请选择");
                    } else {
                        onResultClick.result(selectList, null,null);
                    }

                }
            }
        });

        resetView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        mainBusinessAdapter = new MainBusinessAdapter(mContext, null);
        mainBusinessAdapter.setMultiSelect(true);
        mainBusinessAdapter.setDefItem(-1);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.setAdapter(mainBusinessAdapter);
        mainBusinessAdapter.setOnItemMultiClick(new BaseRecycleAdapter.OnItemMultiClick<String>() {
            @Override
            public void onItemMultiClick(List<String> strings, int position) {
                selectList = strings;
            }
        });

    }

    public void setData(List<String> test, boolean isChange) {
        this.test = test;
        this.isChange = isChange;
        if (isChange) {
            mainBusinessAdapter.resetCheckDatas();
        }
        mainBusinessAdapter.setDatas(this.test);
    }
}
